package org.skypilotplugin.util;

import java.rmi.RemoteException;
import java.sql.SQLException;

import javax.xml.rpc.ServiceException;
import org.dashboard.bean.WSDERBYDashBoard;
import org.dashboard.bean.WSDERBYDashBoardService;
import org.dashboard.bean.WSDERBYDashBoardServiceLocator;

public class ConsumingService {
	public void addText(String strComponent, String strText, String strNameKey){
		 try {
			 	WSDERBYDashBoardService service = new WSDERBYDashBoardServiceLocator();
				WSDERBYDashBoard msg = (WSDERBYDashBoard) service.getWSDERBYDashBoard();
				msg.insertText(strComponent, strText, strNameKey);
			} catch (ServiceException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (RemoteException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
	}
	
	public void deleteText(int id){
		 try {
			    //System.setProperty("http.proxyHost", "localhost");
				//System.setProperty("http.proxyPort", "8080"); 
				WSDERBYDashBoardService service = new WSDERBYDashBoardServiceLocator();
				WSDERBYDashBoard msg = (WSDERBYDashBoard) service.getWSDERBYDashBoard();
			    msg.delete(id);
			} catch (ServiceException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (RemoteException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
	}
	
	public void editText(String strComponent, String strText, String strNameKey){
		 try {
			    
			 	WSDERBYDashBoardService service = new WSDERBYDashBoardServiceLocator();
				WSDERBYDashBoard msg = (WSDERBYDashBoard) service.getWSDERBYDashBoard();
				msg.updateText(strComponent, strText, strNameKey);
			} catch (ServiceException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (RemoteException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
	}
	
	public String[] selectText(String field){
		  String[] query = null;
			
			try {
				//Calling WebService
				WSDERBYDashBoardService service = new WSDERBYDashBoardServiceLocator();
				WSDERBYDashBoard msg;
				msg = (WSDERBYDashBoard) service.getWSDERBYDashBoard();
			    query = msg.queryText(field);
			} catch (ServiceException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (RemoteException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		return query;
	}
	public int selectQTDPOSTIT(){
		 int retQtd = 0;
			
			try {
				//Calling WebService
				WSDERBYDashBoardService service = new WSDERBYDashBoardServiceLocator();
				WSDERBYDashBoard	msg = (WSDERBYDashBoard) service.getWSDERBYDashBoard();
			    retQtd = msg.selectQTD();
			} catch (ServiceException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (RemoteException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		return retQtd;
	}

}
